package common.components
{
	import mx.controls.AdvancedDataGrid;
	import mx.controls.Label;
	import mx.controls.advancedDataGridClasses.AdvancedDataGridListData;
	
	public class AdvancedPercentageRenderer extends Label
	{
		override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void 
		{
			super.updateDisplayList(unscaledWidth, unscaledHeight); 
			var fillColor:uint = 0xFF8000;
		    var grid1:AdvancedDataGrid = AdvancedDataGrid(AdvancedDataGridListData(listData).owner);
		    var value:String = data[AdvancedDataGridListData(listData).dataField];
		    var percentage:Number = 0;
		    var values:Array = value.split("/");
		    if (values.length <= 1)
		    	percentage = 0;
		    else{
		    	if (Number(values[1]) == 0 || isNaN(values[0]) || isNaN(value[1]))
		    		percentage = 0;
		    	else
		    		percentage = Number(value[0]) / Number(value[1]);
		    }
		    if (percentage > 1)
		    	percentage = 1;
	    	
	    	this.graphics.clear();
		    this.graphics.beginFill(fillColor, 0.8);
		    this.graphics.drawRect(0, 0, unscaledWidth * percentage, unscaledHeight + 2);
		    this.graphics.endFill();
		} 

	}
}